package com.ruima.framework.db.impl;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ruima.framework.dao.DaoUtil;
import com.ruima.framework.dao.IRmSysUser;
import com.ruima.framework.entity.RmSysUser;

public class RmSysUserImpl implements IRmSysUser {

	private static Log LOG = LogFactory.getLog(RmSysUserImpl.class);
	
	public List<RmSysUser> getRmSysUsers() throws SQLException{
		List<RmSysUser> list = new ArrayList<RmSysUser>();
		
		String execSql = "select * from rm_sys_user";
		
		LOG.info(String.format("exec the sql [%s],time: [%s]", execSql,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date())));
		CachedRowSet crs = DaoUtil.SimpleQuery(execSql); 
		
		while(crs.next()){
			RmSysUser rmSysUser  = new RmSysUser();
			rmSysUser.setObjid(crs.getString("objid"));
			rmSysUser.setDisindex(crs.getString("disindex"));
			rmSysUser.setName(crs.getString("name"));
			rmSysUser.setCode(crs.getString("code"));
			rmSysUser.setDescript(crs.getString("descript"));
			rmSysUser.setCreatetime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(crs.getDate("createtime"))); 
			rmSysUser.setUpdatetime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(crs.getDate("updatetime")));

			rmSysUser.setEmail(crs.getString("email"));
			rmSysUser.setBirthday(new SimpleDateFormat("yyyy-MM-dd").format(crs.getDate("birthday")));
			rmSysUser.setIdentificationId(crs.getString("identificationId"));
			rmSysUser.setCreateuserObjid(crs.getString("createuserObjid"));
			
			list.add(rmSysUser);
		}
		
		return list;
	}
	public static void main(String[] args) throws SQLException {
		new RmSysUserImpl().getRmSysUsers();
	}
}
